/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Global;

import MainProgram.Console.ErrorConsole;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;

/**
 *
 * @author Stephen
 */
public class CImageIO
{
    public static void SaveImageToFile(Image image, File file)
    {
        try
        {
            if (image instanceof RenderedImage)
                ImageIO.write((RenderedImage) image, "png", file);
            else
            {
                BufferedImage finalImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
                finalImage.getGraphics().drawImage(image, 0, 0, null);
                ImageIO.write(finalImage, "png", file);
            }
        }
        catch (Exception ex)
        {
            ErrorConsole.getConsole().appendError(ex);
        }
    }
    
    public static Image LoadImageFromFile(File file)
    {
        try
        {
            return ImageIO.read(file);
        }
        catch (Exception ex)
        {
            ErrorConsole.getConsole().appendError(ex);
            return null;
        }
    }
}
